<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>密码强度验证</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            list-style: none;
        }

        .box {
            width: 200px;
            margin: 50px auto;
            padding: 10px;
            border: 1px solid red;
        }

        input {
            width: 100%;
            box-sizing: border-box;
        }

        ul {
            width: 100%;
            display: flex;
            justify-content: space-between;
            margin-top: 10px;
        }

        li {
            width: 50px;
            text-align: center;
            /* background-color: red; */
        }

        .easy li:nth-child(1) {
            background-color: rgb(255, 247, 0);

        }

        .common li:nth-child(2) {
            background-color: rgb(21, 255, 0);

        }

        .hard li:nth-child(3) {
            background-color: red;

        }
    </style>
</head>

<body>
    <div class="box">
        <input type="text">
        <ul class="">
            <li>弱</li>
            <li>中</li>
            <li>强</li>
        </ul>
    </div>
</body>
<script>
    let ul = document.querySelector('ul');

    let reg1 = /^\d*$|^[a-z]*$|^[_$@#]*$/;
    let reg2 = /^[0-9a-zA-z]*$|^[0-9_$@#]*$|^[a-zA-Z_$@#]*$/;
    let reg3 = /^[0-9a-zA-z_$@#]*$/;
    console.log(reg1.test('asd'));
    let inp = document.querySelector('.box>input');
    inp.addEventListener('keyup', (e) => {
        if(e.target.value == ' ' || e.target.value.indexOf(' '))
            console.log(123);
        ;

        if (reg1.test(e.target.value)) {
            ul.classList.add('easy')
            ul.classList.remove('common')
            ul.classList.remove('hard');
        }
        else if (reg2.test(e.target.value)) {
            ul.classList.add('common')
            ul.classList.remove('hard');
        } else if (reg3.test(e.target.value))
            ul.classList.add('hard');

        if (!e.target.value) {
            ul.classList.remove('easy')
            ul.classList.remove('common')
            ul.classList.remove('hard');
            return;
        };
    })
</script>

</html>